package com.hepinghospital.user.ui.fragment;//package qd.com.yl.ui.fragment;
//
//import android.graphics.Canvas;
//import android.graphics.Rect;
//import android.os.Bundle;
//import android.support.v7.widget.LinearLayoutManager;
//import android.support.v7.widget.RecyclerView;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.ViewGroup;
//import android.widget.TextView;
//import android.widget.Toast;
//
//import com.rest.business.RestProxy;
//import com.rest.exception.BusinessException;
//import com.rest.response.ConsulationResponse;
//import com.rest.response.Patient;
//import com.rest.response.ReferralResponse;
//import com.scwang.smartrefresh.layout.api.RefreshLayout;
//import com.scwang.smartrefresh.layout.constant.SpinnerStyle;
//import com.scwang.smartrefresh.layout.footer.BallPulseFooter;
//import com.scwang.smartrefresh.layout.header.ClassicsHeader;
//import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
//import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
//
//import java.util.ArrayList;
//import java.util.List;
//
//import butterknife.BindView;
//import io.reactivex.Observer;
//import io.reactivex.disposables.Disposable;
//import jz.joyoung.robot.util.PreferencesHelper;
//import qd.com.yl.R;
//import qd.com.yl.base.BaseApplication;
//import qd.com.yl.base.BaseFragment;
//import qd.com.yl.ui.PatientDetailActivity;
//
///**
// * Created by Administrator on 2018/5/28.
// */
//
//public class HistoryChildFragment extends BaseFragment {
//
//    int type;
//
//    @BindView(R.id.refreshLayout)
//    RefreshLayout refreshLayout;
//    @BindView(R.id.recyclerView)
//    RecyclerView recyclerView;
//
//    MyAdapter adapter;
//
//    List<Patient> list = new ArrayList<>();
//
//    @Override
//    protected int getLayoutResource() {
//        return R.layout.fragment_child;
//    }
//
//    @Override
//    protected void initView() {
//        LinearLayoutManager manager = new LinearLayoutManager(getActivity());
//        manager.setOrientation(LinearLayoutManager.VERTICAL);
//        recyclerView.setLayoutManager(manager);
//        adapter = new MyAdapter();
//        recyclerView.setAdapter(adapter);
//        recyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
//            @Override
//            public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
//                super.onDraw(c, parent, state);
//            }
//
//            @Override
//            public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
//                super.getItemOffsets(outRect, view, parent, state);
//                outRect.bottom = 1;
//            }
//        });
//
//        refreshLayout.setRefreshFooter(new BallPulseFooter(getActivity()).setSpinnerStyle(SpinnerStyle.Scale));
//        refreshLayout.setRefreshHeader(new ClassicsHeader(getActivity()));
//        refreshLayout.setEnableLoadMore(false);
//        refreshLayout.setOnRefreshListener(new OnRefreshListener() {
//            @Override
//            public void onRefresh(RefreshLayout refreshlayout) {
//                initData();
//            }
//        });
//        refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
//            @Override
//            public void onLoadMore(RefreshLayout refreshlayout) {
//
//            }
//        });
//    }
//
//    @Override
//    protected void initData() {
//        type = getArguments().getInt("TYPE");
//        if (type == 0) {
//                getReferralHistoryBaseList();
//        } else if (type == 1) {
//            getConsultationHistoryList();
//        } else if (type == 2) {
//            getVideoConsultationHistoryList();
//        }
//    }
//
//    public static HistoryChildFragment newInstance(int type) {
//        Bundle args = new Bundle();
//        args.putInt("TYPE", type);
//        HistoryChildFragment fragment = new HistoryChildFragment();
//        fragment.setArguments(args);
//        return fragment;
//    }
//
//
//    class MyAdapter extends RecyclerView.Adapter<MyAdapter.Holder> {
//
//        @Override
//        public MyAdapter.Holder onCreateViewHolder(ViewGroup parent, int viewType) {
//            MyAdapter.Holder myHolder;
//            if (type == 0) {
//                myHolder = new MyAdapter.Holder(LayoutInflater.from(getActivity()).inflate(R.layout.item_consultation, parent, false));
//            } else {
//                myHolder = new MyAdapter.Holder(LayoutInflater.from(getActivity()).inflate(R.layout.item_consultation, parent, false));
//            }
//            return myHolder;
//        }
//
//        @Override
//        public void onBindViewHolder(MyAdapter.Holder holder, final int position) {
//            holder.tv_hint.setVisibility(View.VISIBLE);
//            holder.itemView.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    Bundle bundle = new Bundle();
//                    bundle.putInt("type", type + 2);
//                    bundle.putSerializable("obj", list.get(position));
//                    startActivity(PatientDetailActivity.class, bundle);
//                }
//            });
//            holder.tv_reason.setText(list.get(position).medhisZs);
//            holder.tv_time.setText(list.get(position).createDate);
//            holder.tv_patient_name.setText(list.get(position).patientName);
//            holder.tv_hint.setText(list.get(position).getHint());
//            holder.tv_patient_age.setText(list.get(position).getAge());
//            holder.tv_patient_gender.setText(list.get(position).patientSex);
//            holder.tv_hospital.setText(list.get(position).initiatorHosName);
//            holder.button1.setText("查看详情");
//        }
//
//        @Override
//        public int getItemCount() {
//            return list.size();
//        }
//
//        class Holder extends RecyclerView.ViewHolder {
//
//            TextView tv_reason, tv_time, tv_id_card, tv_patient_name, tv_hint, tv_patient_gender, tv_patient_age, button1,tv_hospital;
//
//            public Holder(View itemView) {
//                super(itemView);
//                tv_reason = itemView.findViewById(R.id.tv_reason);
//                tv_time = itemView.findViewById(R.id.tv_time);
//                tv_id_card = itemView.findViewById(R.id.tv_id_card);
//                tv_patient_name = itemView.findViewById(R.id.tv_patient_name);
//                tv_hint = itemView.findViewById(R.id.tv_hint);
//                tv_patient_gender = itemView.findViewById(R.id.tv_patient_gender);
//                tv_patient_age = itemView.findViewById(R.id.tv_patient_age);
//                tv_hospital = itemView.findViewById(R.id.tv_hospital);
//                button1 = itemView.findViewById(R.id.button1);
//            }
//        }
//    }
//
//    private void getReferralHistoryProList() {
//        RestProxy.getInstance().getReferralHistoryProList(PreferencesHelper.getInstance().getString(getActivity(), "username"), PreferencesHelper.getInstance().getString(getActivity(), "id"), new Observer<ReferralResponse>() {
//            @Override
//            public void onSubscribe(Disposable d) {
//
//            }
//
//            @Override
//            public void onNext(ReferralResponse referralResponse) {
//                list.clear();
//                list.addAll(referralResponse.data);
//                adapter.notifyDataSetChanged();
//            }
//
//            @Override
//            public void onError(Throwable e) {
//                refreshLayout.finishLoadMore(true/*,false*/);//传入false表示加载失败
//                refreshLayout.finishRefresh(true/*,false*/);//传入false表示加载失败
//            }
//
//            @Override
//            public void onComplete() {
//                refreshLayout.finishLoadMore(true/*,false*/);//传入false表示加载失败
//                refreshLayout.finishRefresh(true/*,false*/);//传入false表示加载失败
//            }
//        });
//    }
//
//    private void getReferralHistoryBaseList() {
//        RestProxy.getInstance().getReferralHistoryBaseList(PreferencesHelper.getInstance().getString(getActivity(), "username"), PreferencesHelper.getInstance().getString(getActivity(), "id"), new Observer<ReferralResponse>() {
//            @Override
//            public void onSubscribe(Disposable d) {
//
//            }
//
//            @Override
//            public void onNext(ReferralResponse referralResponse) {
//                list.clear();
//                list.addAll(referralResponse.data);
//                adapter.notifyDataSetChanged();
//            }
//
//            @Override
//            public void onError(Throwable e) {
//                refreshLayout.finishLoadMore(true/*,false*/);//传入false表示加载失败
//                refreshLayout.finishRefresh(true/*,false*/);//传入false表示加载失败
//                if(e instanceof BusinessException){
//                    if(((BusinessException)e).errorCode == 700){
//                        Toast.makeText(getActivity(),"登录失败，请重新登录",Toast.LENGTH_SHORT).show();
//                    }
//                }
//            }
//
//            @Override
//            public void onComplete() {
//                refreshLayout.finishLoadMore(true/*,false*/);//传入false表示加载失败
//                refreshLayout.finishRefresh(true/*,false*/);//传入false表示加载失败
//            }
//        });
//    }
//
//
//    private void getConsultationHistoryList() {
//        RestProxy.getInstance().getConsultationList("1", "50", "2", "101", new Observer<ConsulationResponse>() {
//            @Override
//            public void onSubscribe(Disposable d) {
//
//            }
//
//            @Override
//            public void onNext(ConsulationResponse consulationResponse) {
//                list.clear();
//                list.addAll(consulationResponse.data.records);
//                adapter.notifyDataSetChanged();
//            }
//
//            @Override
//            public void onError(Throwable e) {
//                refreshLayout.finishLoadMore(true/*,false*/);//传入false表示加载失败
//                refreshLayout.finishRefresh(true/*,false*/);//传入false表示加载失败
//                if(e instanceof BusinessException){
//                    if(((BusinessException)e).errorCode == 700){
//                        Toast.makeText(getActivity(),"登录失败，请重新登录",Toast.LENGTH_SHORT).show();
//                    }
//                }
//            }
//
//            @Override
//            public void onComplete() {
//                refreshLayout.finishLoadMore(true/*,false*/);//传入false表示加载失败
//                refreshLayout.finishRefresh(true/*,false*/);//传入false表示加载失败
//            }
//        });
//    }
//
//
//    private void getVideoConsultationHistoryList() {
//        RestProxy.getInstance().getConsultationList("1", "50", "1", "101", new Observer<ConsulationResponse>() {
//            @Override
//            public void onSubscribe(Disposable d) {
//
//            }
//
//            @Override
//            public void onNext(ConsulationResponse consulationResponse) {
//                list.clear();
//                list.addAll(consulationResponse.data.records);
//                adapter.notifyDataSetChanged();
//            }
//
//            @Override
//            public void onError(Throwable e) {
//                refreshLayout.finishLoadMore(true/*,false*/);//传入false表示加载失败
//                refreshLayout.finishRefresh(true/*,false*/);//传入false表示加载失败
//                if(e instanceof BusinessException){
//                    if(((BusinessException)e).errorCode == 700){
//                        Toast.makeText(getActivity(),"登录失败，请重新登录",Toast.LENGTH_SHORT).show();
//                    }
//                }
//            }
//
//            @Override
//            public void onComplete() {
//                refreshLayout.finishLoadMore(true/*,false*/);//传入false表示加载失败
//                refreshLayout.finishRefresh(true/*,false*/);//传入false表示加载失败
//            }
//        });
//    }
//
//    @Override
//    public void setUserVisibleHint(boolean isVisibleToUser) {
//        super.setUserVisibleHint(isVisibleToUser);
//        if (getUserVisibleHint()) {
//            if (type == 0) {
//                    getReferralHistoryBaseList();
//            } else if (type == 1) {
//                getConsultationHistoryList();
//            } else if (type == 2) {
//                getVideoConsultationHistoryList();
//            }
//        } else {
////            System.out.println("不可见");
//        }
//    }
//
//}
